package com.lemon.core.base.result;

import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 默认响应码实现
 *
 * @author pan
 * @since 2016-07-23
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IResultCode, Serializable {

    /**
     * 操作成功
     */
    SUCCESS(200, "SUCCESS"),

    TENANT_ID_EMPTY(100000, "租户编号不能为空"),

    USER_ERROR(100001, "用户端错误"),
    USER_LOGIN_ERROR(100200, "用户登录异常"),

    USER_NOT_EXIST(100201, "用户不存在"),
    USER_ACCOUNT_LOCKED(100202, "用户账户被冻结"),
    USER_ACCOUNT_INVALID(100203, "用户账户已失效"),
    USER_ACCOUNT_EXPIRED(100204, "用户账户已过期"),

    USERNAME_OR_PASSWORD_ERROR(100210, "用户名或密码错误"),
    PASSWORD_ENTER_EXCEED_LIMIT(100211, "用户输入密码次数超限"),
    CLIENT_AUTHENTICATION_FAILED(100212, "客户端认证失败"),
    CAPTCHA_VERIFY_ERROR(100213, "验证码不正确"),
    CAPTCHA_EMPTY_ERROR(100214, "验证码不能为空"),
    TOKEN_INVALID_OR_EXPIRED(100230, "token无效或已过期"),
    TOKEN_ACCESS_FORBIDDEN(100231, "token已被禁止访问"),

    AUTHORIZED_ERROR(100300, "访问权限异常"),
    ACCESS_UNAUTHORIZED(100301, "访问未授权"),
    FORBIDDEN_OPERATION(100302, "演示环境禁止修改、删除重要数据，请本地部署后测试"),


    PARAM_ERROR(100400, "用户请求参数错误"),
    RESOURCE_NOT_FOUND(100401, "请求资源不存在"),
    PARAM_IS_NULL(100410, "请求必填参数为空"),

    USER_UPLOAD_FILE_ERROR(100700, "用户上传文件异常"),
    USER_UPLOAD_FILE_TYPE_NOT_MATCH(100701, "用户上传文件类型不匹配"),
    USER_UPLOAD_FILE_SIZE_EXCEEDS(100702, "用户上传文件太大"),
    USER_UPLOAD_IMAGE_SIZE_EXCEEDS(100703, "用户上传图片太大"),

    SYSTEM_EXECUTION_ERROR(200001, "系统执行出错"),
    SYSTEM_EXECUTION_TIMEOUT(200100, "系统执行超时"),
    SYSTEM_ORDER_PROCESSING_TIMEOUT(200100, "系统订单处理超时"),

    SYSTEM_DISASTER_RECOVERY_TRIGGER(200200, "系统容灾功能被触发"),
    FLOW_LIMITING(200210, "系统限流"),
    DEGRADATION(200220, "系统功能降级"),

    SYSTEM_RESOURCE_ERROR(200300, "系统资源异常"),
    SYSTEM_RESOURCE_EXHAUSTION(200310, "系统资源耗尽"),
    SYSTEM_RESOURCE_ACCESS_ERROR(200320, "系统资源访问异常"),
    SYSTEM_READ_DISK_FILE_ERROR(200321, "系统读取磁盘文件失败"),

    CALL_THIRD_PARTY_SERVICE_ERROR(300001, "调用第三方服务出错"),
    MIDDLEWARE_SERVICE_ERROR(300100, "中间件服务出错"),
    INTERFACE_NOT_EXIST(300113, "接口不存在"),

    MESSAGE_SERVICE_ERROR(300120, "消息服务出错"),
    MESSAGE_DELIVERY_ERROR(300121, "消息投递出错"),
    MESSAGE_CONSUMPTION_ERROR(300122, "消息消费出错"),
    MESSAGE_SUBSCRIPTION_ERROR(300123, "消息订阅出错"),
    MESSAGE_GROUP_NOT_FOUND(300124, "消息分组未查到"),

    DATABASE_ERROR(300300, "数据库服务出错"),
    DATABASE_TABLE_NOT_EXIST(300311, "表不存在"),
    DATABASE_COLUMN_NOT_EXIST(300312, "列不存在"),
    DATABASE_DUPLICATE_COLUMN_NAME(300321, "多表关联中存在多个相同名称的列"),
    DATABASE_DEADLOCK(300331, "数据库死锁"),
    DATABASE_PRIMARY_KEY_CONFLICT(300341, "主键冲突");

    private int code;

    private String msg;

    public static ResultCode getValue(int code) {
        for (ResultCode value : values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        // 默认系统执行错误
        return SYSTEM_EXECUTION_ERROR;
    }
}
